package yw.nmh.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import yw.nmh.dicInfo.dto.DicInfoDTO;
import yw.nmh.dicInfo.dto.DicUpdateStatusDTO;
import yw.nmh.result.R;
import yw.nmh.service.DicInfoService;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "字典管理", description = "字典管理相关接口")
@RequestMapping("/dic")
public class DicInfoController {
    @Resource
    private DicInfoService dicInfoService;
    @Operation(summary = "字典目录查询", description = "字典目录查询接口")
    @PostMapping("/list")
    public R listNames(){
        List<String> names = dicInfoService.DicNames();
        return R.OK(names);
    }

    @Operation(summary = "新增字典目录", description = "新增字典目录接口")
    @PostMapping("/addDic")
    public R addDic(@RequestBody DicInfoDTO dicInfoDTO){
        if (dicInfoService.addDic(dicInfoDTO)){
            return R.OK();
        }
        return R.FAIL("字典已存在");
    }

    @Operation(summary = "修改状态", description = "修改状态接口")
    @PostMapping("/updateStatus")
    public R updateStatus(@RequestBody DicUpdateStatusDTO dicUpdateStatusDTO){
        if (dicInfoService.updateStatus(dicUpdateStatusDTO)){
            return R.OK();
        }
        return R.FAIL();
    }
}
